<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %> 
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>挂车项目列表</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
              <div class="fieldBox" >
                <div class="label">厂商名称</div>
                <div class="field">
                  <input name="mfr" id="mfr" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车辆用途</div>
                <div class="field">
                    <input name="carUsage" id="carUsage" type="text" class="ui-textbox" value="" placeholder="请选择"  ltype="combobox">
                </div>
            </div>

            <div class="fieldBox" >
                <div class="label">公告型号</div>
                <div class="field">
                    <input name="styleBulletinModel" id="styleBulletinModel" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox" >
                <div class="label">车型ID</div>
                <div class="field">
                    <input name="styleBulletinModel" id="styleId" type="text"   class="ui-textbox" value="">
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox">
               <span id="searchBtn" class="sq-button sq-button-round" onclick="searchBtn()">查询</span>
              <span id="clearBtn" class="sq-button sq-button-round" onclick="clearBtn()">清空</span>
             <span id="detailBtn" class="sq-button sq-button-round" onclick="detailBtn()">确定</span>
            </div>
        </div>
    </form>
</div>
<div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
	var grid = null;
	var prjId= '${prjId}';
    var prdId= '${prdId}';
    var insRoutePrdId='${insRoutePrdId}';
	var mfrComboBox = null;
	var carUsageComboBox = null ;
	$(function () {
		// 初始化厂商下拉
        initMfr();
        mfrComboBox = liger.get("mfr");
        initCarUsage();
        carUsageComboBox = liger.get("carUsage");
	});

    /**
     * 初始化品牌下拉信息
     */
	function initMfr(){
        $("#mfr").ligerComboBox({
            url: '<%=path%>/vehicle/trailer/mfrList.do',
            ajaxType: "get",
            parms:{},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            }
        });
    }
    /**
     * 初始化用途下拉
     */
    function initCarUsage(){
        $("#carUsage").ligerComboBox({
            url: '<%=path%>/vehicle/trailer/trailerUsageList.do',
            ajaxType: "get",
            async:false,
            parms:{},
            width: 120,
            valueField: 'key',
            textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onSuccess: function(e){
                carUsageComboBox.setValue(prdId);
                searchBtn();
            }
        });
    }

    /**
     * 获取comboBox的值
     * @param comboBox
     * @returns {null}
     */
    function getComboBoxValue(comboBox){
        if(comboBox){
            var selected = comboBox.getValue();
            if(selected){
                return selected;
            }
        }
        return null;
    }
	//根据产品类型加载不同的grid
	function prdGrid(prdType,parms){
        // 厂商id
        var mfrId = getComboBoxValue(mfrComboBox);
        // 用途id
        var usageId = getComboBoxValue(carUsageComboBox);
        // 车型ID
        var id = $("#styleId").val();
        // 公告型号
        var styleBulletinModel = $("#styleBulletinModel").val();
        $("#ligergrid1").ligerGrid({
            url: '<%=path%>/vehicle/trailer/initList.do',
            method : 'get',
            parms : {modelid:mfrId,stylePurposeId:usageId,styleBulletinModel:styleBulletinModel,id:id},
            columns: [
                { display: '车型名称', name: 'styleName', minWidth: 150 ,
                    enabledSort:true},
                { display: '车型ID', name: 'id', minWidth: 150 ,
                    enabledSort:true},
                { display: '产品名称', name: 'stylePurposeName', minWidth: 150 ,
                    enabledSort:true},
                { display: '参考价', name: 'styleMsrp', width: 100,
                    render: function (rowdata, rowindex, value, column) {
                        if(value){
                            var h = value + "万元";
                            return h;
                        }
                    },
                    enabledSort:true},
                // { display: '产品类型', name: 'stylePurposeId', minWidth: 150 , enabledSort:true},
                { display: '车身长度', name: 'styleLength', minWidth: 100 , enabledSort:true},
                { display: '罐体容积', name: 'tankVol', minWidth: 100 , enabledSort:true},
                { display: '车桥数量', name: 'bridgeNum', minWidth: 100 , enabledSort:true},
                { display: '车桥品牌', name: 'bridgeBrand', minWidth: 140 , enabledSort:true},
                { display: '轮胎规格', name: 'mWhlSpec', minWidth: 140 , enabledSort:true},
                { display: '轮胎数量', name: 'whlNum', minWidth: 140 , enabledSort:true},
            ],
            pageSize:10,
            root:'rows',
            record:'total',
            hideLoadButton : true,
            width: '100%',
            height:'100%',
            heightDiff:-2,
            //isScroll: false,
            checkbox:true,
            rownumbers:true
        });
		grid = liger.get("ligergrid1");
	}

	function searchBtn(){
        // TODO
        var selected = mfrComboBox.getValue();
        var selected2 = carUsageComboBox.getValue();
        prdGrid();
	}
	
	function detailBtn(){
		var prdCd = null;
		var bizTypCd = null;
		var bizCd = null;
		var sGrpCd = null;
		var sCode = null;
		var prdTypCdNm = null
		
		var selectedRows = grid.getSelectedRows();
		if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}

		
		var callback = frameElement.dialog.get("callback");
		var id = selectedRows[0].id;
        var purposeCd = selectedRows[0].stylePurposeId;
		//var prdTypCd= selectedRows[0].prdTypCd;
		//var prdCd = selectedRows[0].prdBscInfoVO.prdCd;
		parent.Add_navTab('tab_project_prd_detail'+id,'项目产品详细信息','<%=path%>/project/vehicle/toPrjPrdDetailPage.do?id='+id+'&&prjId='+prjId + '&&purposeCd='+purposeCd + '&&insRoutePrdId=' + insRoutePrdId,callback);
		parent.$.ligerDialog.close();
		parent.$(".l-dialog,.l-window-mask").css("display","none"); 
	}
	
	function clearBtn(){
        mfrComboBox.setValue("");
        carUsageComboBox.setValue("")
        $("#styleBulletinModel").val("");
        $("#styleId").val("");
	}
	
	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}
    //格式化时间
    function renderDate(rowdata, index, value){
        var dateStr = "";
        if(null != value){
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }


</script>

</body>
</html>